package com.yuyuan.notice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.yuyuan.common.domain.Result;
import com.yuyuan.common.utils.UserHolder;
import com.yuyuan.notice.domain.po.Notice;
import com.yuyuan.notice.mapper.NoticeMapper;
import com.yuyuan.notice.service.INoticeService;
import com.yuyuan.notice.utils.MyUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: kestrel
 * @Version:1.0
 * @Date: 2024/6/20
 */
@Slf4j
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    @Autowired
    private MyUtils myUtils;

    @Override
    public Result getPageNotices(Long startId) {
        long userId = UserHolder.getUser().getId();
        //分页查询传入0时默认读取最新(最迟创建)数据，进行处理
        startId = myUtils.zeroHandler(startId, userId, "NoticeDTOC");
        List<Notice> list = noticeMapper.getPageByBlogId(userId,startId);
        //返回结果以及长度
        return Result.ok(list,((Integer)(list.size())).longValue());
    }
}
